/*
 * Copyright 2006-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package asphalt2.action.error
{
	import asphalt2.validator.IValidateError;
	
	import flash.events.Event;
	
	import mx.controls.Alert;
	import mx.core.UIComponent;
	/**
	 * エラー時にアラート表示するErrorDisplay
	 *
	 * @author c9katayama
	 */
	public class AlertErroDisplay implements IErrorDisplay
	{
		protected var _title:String;
		protected var _errorMessageDispNum:int;
		
		public function AlertErroDisplay(errorMessageDispNum:int = 1,title:String = "エラー"){
			_errorMessageDispNum = errorMessageDispNum;			 
			_title = title;			
		}

		public function resetErrorDisplay():void{
		}
		
		public function displayError(error:IValidateError, eventSource:Object=null):void{
			
			var message:String = "";
			var errors:Array = error.getErrors();
			for(var i:int = 0,size:int = errors.length;i < size;i++){
				if(i < _errorMessageDispNum){
					if(i!=0){
						message += "\n";
					}
					message += errors[i].message;
				}else{
					break;
				}
			}					
			Alert.show(message,_title,Alert.OK,null,function(e:Event):void{
				UIComponent(errors[0].component).setFocus();
			});	
		}
				
		public function dispose():void{
		}
		
	}
}